###########################################################################
### Table 2. Average Value of Child-to-Parent Financial Transfer, China ###
###########################################################################

load("/Users/Yannan/Desktop/data_china.RData")

library(dplyr)

## create variable recording average value of financial transfer
data_china$fin_avg <- rowMeans(data_china[, 5:8], na.rm = T)

## create categorical variable of parent's age
data_china$age_cat <- ifelse(data_china$age < 55, "<55", 
                             ifelse(data_china$age < 65, "55-65", 
                                    ifelse(data_china$age < 75, "65-75", 
                                           ifelse(is.na(data_china$age), NA, ">75"))))

## generate cross tabulation
data_china %>%
  group_by(child_gender, gender) %>%
  summarise(mean = mean(fin_avg, na.rm = T), n = n())

data_china %>%
  group_by(child_married, gender) %>%
  summarise(mean = mean(fin_avg, na.rm = T), n = n())

data_china %>%
  group_by(child_education, gender) %>%
  summarise(mean = mean(fin_avg, na.rm = T), n = n())

data_china %>%
  group_by(married, gender) %>%
  summarise(mean = mean(fin_avg, na.rm = T), n = n())

data_china %>%
  group_by(age_cat, gender) %>%
  summarise(mean = mean(fin_avg, na.rm = T), n = n())
